package com.gss.common.util;

import java.io.File;
import java.util.ArrayList;

import javax.annotation.PostConstruct;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

@Component(value="applicationConstants")
public class ApplicationConstants {
	
	private Logger logger = Logger.getLogger(ApplicationConstants.class);
	
	public static boolean isDebug = true;
	public static final String ADMIN_ROLE = "ROLE_DMSADMIN";
	public static final String SUPER_ADMIN_ROLE = "ROLE_SU";

	public static final String REGEX_FOR_EMAIL = "\\b[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b";
	//public static final String REGEX_FOR_PASSWORD = ".[0-9]*.[a-z]*.[A-Z]*.[!@#$%^&]*.{8,}";
	public static final String REGEX_FOR_PASSWORD = "((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&]).{8,})";  //changed on 07 Feb 2012 by ashish as the previous is not working
	public static final String REGEX_FOR_DOC_NAME = "^[a-zA-Z][\\s\\w\\\\\\.]*";
	public static final String REGEX_FOR_DESC = "[\\s\\w\\.,@%'?;:-]*";
	public static final String REGEX_FOR_NAME_ALLOW_BLANK = "[\\s\\w\\.,]*";
	public static final long IMAGE_FILE_SIZE_LIMIT = 1024L * 1024L * 10;
	public static final String lineSeparator = System.getProperty("line.separator");
	public static final String fileSeparator = System.getProperty("file.separator");
	public static final String IMAGES_BASE_FOLDER_NAME = "gdImages";
	public static final String DEFAULT_DATE_PATTERN = "dd-MM-yyyy";
	public static final String DEFAULT_DATE_TIME_PATTERN = "dd-MM-yyyy hh:mm:ss aa";
	public static final String ATTACHMENT_TYPE_GENERAL = "General";
	public static final String ATTACHMENT_TYPE_COSTSHEET = "CostSheet";
	public static final long ATTACHMENT_SIZE_LIMIT = 1024L * 1024L;
	public static final String OPEN_PWD = "openXyZ";
	public static final String EDIT_PWD = "editXyZ";
	
	public static final String DEFAULT_ROLE="ROLE_DMSEU";
	public static final String ROLE_CONTROLLER = "ROLE_APPROVER";
	public static final String ROLE_CENTRAL_CONTROLLER = "ROLE_CC";
	public static final String ROLE_REVIEWER = "ROLE_REVIEWER";
	public static final String ROLE_OWNER = "ROLE_OWNER";
	public static final String ROLE_SUB_OWNER = "ROLE_SO";
	public static final String ROLE_CHIEF_CENTRAL_CONTROLLER = "ROLE_CCC";
	
	//can get from system property
	public static final String VIEW_OP = "1";
	public static final String RENEW_OP = "2";
	public static final String VERSION_OP = "3";
	public static final String LINK_OP = "4";
	public static final String DEACT_OP = "5";
	
	public static ArrayList<String> PERMISSIBLE_IMAGE_TYPES = new ArrayList<String>();
	public static String PATH_TO_CONTEXT_ROOT_FOLDER = "";
	
	public static final Integer ALL_INT = 0;
	public static final long ALL_LONG = Long.parseLong("0");
	public static final String ALL_STRING = "All";
		
	public static int RECORDS_PER_PAGE = 15;

	public static byte[] WATERMARK_TEMPLATE_BYTES;
	public static String WATERMARK_TEMPLATE_FILE_PATH = System.getProperty("templateFilePath", "/usr/gss/watermarkTemplate.pdf");
//	public static final String WATERMARK_TEMPLATE_FILE_PATH = System.getProperty("templateFilePath", "D:/sample.pdf");
	//public static //final String WATERMARK_TEMPLATE_FILE_PATH = "/usr/gss/armory/temp.pdf";
	public static final String NA = "NA";
	public static final String DELIM = "XXOO";
	public static final String EXCEL_2003_FORMAT = "application/vnd.ms-excel";

	public static final String RESTRICTED = "restricted";
	public static final String GROUP_COMPANY = "GroupHead";
	public static final String SUBSIDIARY_COMPANY = "Subsidiary";
	public static final String STANDALONE_COMPANY = "StandAlone";
	
	public static Integer APP_ID = 2;
	
	public static final String FORM_CHANGE_PERMISSION = "changePermission";
	
	public static final String ENABLE_FUNCTION = "1";
	public static final String DISABLE_FUNCTION = "0";
	
	public static final String FORM_OLD = "old_form";
	public static final String FORM_NEW = "new_form";
	
	@PostConstruct
	public void initMethod(){
		File tempFile = null;
		try {
			tempFile = new File(this.getClass().getResource("/watermarktemplate.pdf").toURI());
			String tempPath =  tempFile.getCanonicalPath();
			logger.debug("tempPath" + tempPath);
			WATERMARK_TEMPLATE_FILE_PATH = tempPath;
			tempPath = tempPath.substring(0, tempPath.indexOf("WEB-INF"));
			logger.debug("Deployment Path : " + tempPath);
			PATH_TO_CONTEXT_ROOT_FOLDER = tempPath;
		} catch (Exception e1) {
			logger.error(e1.getMessage());
		}
		finally{
			if(null != tempFile){
				tempFile = null;
			}
		}
	}
	
}
